package com.jdrx.sw.sewage.service;

import com.google.common.collect.Maps;
import com.jdrx.platform.commons.rest.exception.BizException;
import com.jdrx.sw.sewage.beans.entity.DictClassifyPO;
import com.jdrx.sw.sewage.common.util.Asserts;
import com.jdrx.sw.sewage.dao.DictClassifyDao;
import com.jdrx.sw.sewage.service.base.BaseServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import static com.google.common.collect.ImmutableMap.of;

@Service
public class DictClassifyServiceImpl extends BaseServiceImpl {

    private static final Logger logger = LoggerFactory.getLogger(DictClassifyServiceImpl.class);

    @Autowired
    private DictClassifyDao dictClassifyDao;
    @Autowired
    private OcpServiceImpl ocpServiceImpl;

    /**
     * 查询所有字典表分类
     *
     * @return
     * @throws BizException
     */
    public List<DictClassifyPO> findAll() throws BizException {
        Map<String, Object> params = Maps.newHashMap();
        try {
            return dictClassifyDao.findAll(params);
        } catch (Exception e) {
            logger.error("查询失败", e);
            throw new BizException("查询失败");
        }
    }


    /**
     * 根据参数获取DictClassifyPO对象
     * @param params
     * @return
     * @throws BizException
     */
    public DictClassifyPO getByParams(Map<String, Object> params) throws BizException {
        Asserts.notNull(params, "参数");
        try {
            return dictClassifyDao.getByParmas(params);
        } catch (Exception e) {
            logger.error("查询失败", e);
            throw new BizException("查询失败");
        }
    }

    /**
     * 根据参数获取DictClassifyPO对象
     * @param id
     * @return
     * @throws BizException
     */
    public DictClassifyPO getById(Long id) throws BizException {
        Asserts.notNull(id, "id");
        try {
            return dictClassifyDao.getByParmas(of("id",id));
        } catch (Exception e) {
            logger.error("查询失败", e);
            throw new BizException("查询失败");
        }
    }
}
